package com.qding.park.manager.app.queue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.manager.app.queue.handle.CarInckeckHandle;
import com.qding.park.manager.app.queue.handle.CarLockTimeOutHandle;
import com.qding.park.manager.app.queue.handle.CarOutckeckHandle;
import com.qding.park.manager.app.queue.handle.CarlockOutalarmHandle;
import com.qding.park.manager.app.queue.handle.ClearTimeOutOrderHandle;
import com.qding.park.manager.app.queue.handle.ExpireNoticeHandle;
import com.qding.park.manager.app.queue.handle.FailTaskRedoJobHandle;
import com.qding.park.manager.app.queue.handle.InviteInckeckHandle;
import com.qding.park.manager.app.queue.handle.InviteTimeOutHandle;
import com.qding.park.manager.app.queue.handle.MonthPayedHandle;
import com.qding.park.manager.app.queue.handle.OutlineMonthlyReportHandle;
import com.qding.park.manager.app.queue.handle.ParkRuleSyncHandle;
import com.qding.park.manager.app.queue.handle.PassDayReportHandle;
import com.qding.park.manager.app.queue.handle.ReserveDelayTimeoutHandle;
import com.qding.park.manager.app.queue.handle.ReserveInckeckHandle;
import com.qding.park.manager.app.queue.handle.ReservePayedHandle;
import com.qding.park.manager.app.queue.handle.ReserveTimeOutHandle;
import com.qding.park.manager.app.queue.handle.TempPayedHandle;
import com.qding.park.manager.app.queue.handle.TeneratPayedHandle;
import com.qding.park.manager.app.queue.handle.UserInfoSyncHandle;
import com.qding.park.manager.app.queue.util.SpringContextUtil;
import com.qding.park.manager.facade.queue.service.ReportFacade;
import com.qding.park.manager.facade.queue.service.entity.ExceptionParkOutSyncDTO;
import com.qding.park.manager.facade.queue.service.entity.ParkEventSyncDTO;
import com.qding.park.manager.facade.queue.service.entity.ParkInSyncDTO;
import com.qding.park.manager.facade.queue.service.entity.ParkOutRenewalSyncDTO;
import com.qding.park.manager.facade.queue.service.entity.ParkOutSyncDTO;
import com.qding.park.manager.facade.queue.service.entity.RenewalSyncDTO;
import com.qding.park.manager.pojo.TbCarlock;
import com.qding.park.manager.pojo.queue.QueueMsg;
import com.qding.park.manager.pojo.queue.QueueTypeEnum;

/**
  * @ClassName: HandleWrap
  * @Description: 处理包装类
  * @author Comsys-Administrator
  * @date 2016年10月20日 上午11:28:58
  *
  */
public class HandleWrap {
	private static final Log _log = LogFactory.getLog(HandleWrap.class);
	
	public static void  handle(QueueMsg msg){
	    ReportFacade  reportFacade=SpringContextUtil.getApplicationContext().getBean(ReportFacade.class);
	    JSONObject data = (JSONObject) msg.getData();
		if (msg.getEventType() == QueueTypeEnum.BASE_DATA_SYNC.getType()) {
			// 基础数据同步任务消息
			
		} else if (msg.getEventType() == QueueTypeEnum.CARLOCK_TIMEOUT.getType()) {
			// 锁车单超时消息
			_log.info("锁车单超时消息:"+msg);
			CarLockTimeOutHandle carLockHandle = SpringContextUtil.getApplicationContext()
					.getBean(CarLockTimeOutHandle.class);
			carLockHandle.handle(msg);
		} else if (msg.getEventType() == QueueTypeEnum.DATA_IDENTICAL.getType()) {
			// 数据一致性检查消息
		} else if (msg.getEventType() == QueueTypeEnum.FAILTASK_REDO.getType()) {
			// 失败任务重做消息
			_log.info(" 失败任务重做消息 :"+msg);
			FailTaskRedoJobHandle failTaskRedoJobHandle = SpringContextUtil.getApplicationContext()
					.getBean(FailTaskRedoJobHandle.class);
			failTaskRedoJobHandle.handle(msg);
		} else if (msg.getEventType() == QueueTypeEnum.INVITE_TIMEOUT.getType()) {
			// 邀请单超时消息
			_log.info(" 邀请单超时消息 :"+msg);
			InviteTimeOutHandle inviteHandle = SpringContextUtil.getApplicationContext()
					.getBean(InviteTimeOutHandle.class);
			inviteHandle.handle(msg);
		} else if (msg.getEventType() == QueueTypeEnum.PARK_CHARGE_RULE_SYNC.getType()) {
			// 车场计费规则同步任务消息
			_log.info(" 车场计费规则同步任务消息 :"+msg);
			ParkRuleSyncHandle parkRuleSyncHandle = SpringContextUtil.getApplicationContext().getBean(ParkRuleSyncHandle.class);
			parkRuleSyncHandle.handle(msg);
		} else if (msg.getEventType() == QueueTypeEnum.PARKINFO_SYNC.getType()) {
			// 车场数据同步任务消息
		} else if (msg.getEventType() == QueueTypeEnum.RESERVE_TIMEOUT.getType()) {
			// 预定单超时处理消息
			_log.info(" 预定单超时处理消息 :"+msg);
			ReserveTimeOutHandle reserveHandle = SpringContextUtil.getApplicationContext()
					.getBean(ReserveTimeOutHandle.class);
			reserveHandle.handle(msg);
		}else if(msg.getEventType() == QueueTypeEnum.RESERVE_DELAY_TIMEOUT.getType()){
			//预定单延期超时处理消息
			_log.info(" 预定单延期超时处理消息 :"+msg);
			ReserveDelayTimeoutHandle reserveHandle = SpringContextUtil.getApplicationContext()
					.getBean(ReserveDelayTimeoutHandle.class);
			reserveHandle.handle(msg);
		}
		else if(msg.getEventType() == QueueTypeEnum.RESERVE_PAYED.getType()){
			//预定单支付完成
			_log.info(" 预定单支付完成消息 :"+msg);
			ReservePayedHandle reservePayedHandle = SpringContextUtil.getApplicationContext()
					.getBean(ReservePayedHandle.class);
			reservePayedHandle.handle(msg);
		}
		
		else if(msg.getEventType() == QueueTypeEnum.CLEAR_TIMEOUT_ORDER.getType()){
			//清除超时失效订单
			_log.info(" 清除超时失效订单消息 :"+msg);
			ClearTimeOutOrderHandle clearTimeOutOrderHandle = SpringContextUtil.getApplicationContext()
					.getBean(ClearTimeOutOrderHandle.class);
			clearTimeOutOrderHandle.handle(msg);
		}
		
		else if (msg.getEventType() == QueueTypeEnum.USERINFO_SYNC.getType()) {
			// 用户基础数据同步任务消息
			_log.info(" 用户基础数据同步任务消息 :"+msg);
			UserInfoSyncHandle userInfoSyncHandle = SpringContextUtil.getApplicationContext().getBean(UserInfoSyncHandle.class);
			userInfoSyncHandle.handle(msg);
		} 
		else if (msg.getEventType() == QueueTypeEnum.TEMP_PAYMENT_ORDER_PAYED_PARKHANDLE.getType()) {
			//临停缴费 支付完成
			_log.info(" 临停缴费 支付完成消息 :"+msg);
			TempPayedHandle tempPayedHandle = SpringContextUtil.getApplicationContext()
					.getBean(TempPayedHandle.class);
			tempPayedHandle.handle(msg);
		}else if(msg.getEventType() == QueueTypeEnum.MONTHRENT_PAYMENT_ORDER_PAYED_PARKHANDLE.getType()){
			//月租续费支付完成
			_log.info(" 月租续费支付完成消息 :"+msg);
			MonthPayedHandle monthPayedHandle = SpringContextUtil.getApplicationContext()
					.getBean(MonthPayedHandle.class);
			monthPayedHandle.handle(msg);
		}else if(msg.getEventType() == QueueTypeEnum.TENERAT_PAYMENT_ORDER_PAYED_PARKHANDLE.getType()){
			//代缴支付完成
			_log.info(" 代缴支付完成消息 :"+msg);
			TeneratPayedHandle teneratPayedHandle = SpringContextUtil.getApplicationContext()
					.getBean(TeneratPayedHandle.class);
			teneratPayedHandle.handle(msg);
		}
		/******上报处理**********/
		else if (msg.getEventType() == QueueTypeEnum.CAR_OUTCKECK.getType()) {
			// 车辆出场消息
			_log.info(" 车辆出场消息 :"+msg);
			CarOutckeckHandle carOutckeckHandle = SpringContextUtil.getApplicationContext().getBean(CarOutckeckHandle.class);
			carOutckeckHandle.handle(msg);
		} 
		else if (msg.getEventType() == QueueTypeEnum.CAR_INCKECK.getType()) {
			// 车辆进场消息
			_log.info(" 车辆进场消息 :"+msg);
			CarInckeckHandle carInckeckHandle = SpringContextUtil.getApplicationContext().getBean(CarInckeckHandle.class);
			carInckeckHandle.handle(msg);
		} 
		else if (msg.getEventType() == QueueTypeEnum.RESERVE_INCKECK.getType()) {
			// 预定车辆进场消息
			_log.info(" 预定车辆进场消息 :"+msg);
			ReserveInckeckHandle reserveInckeckHandle = SpringContextUtil.getApplicationContext().getBean(ReserveInckeckHandle.class);
			reserveInckeckHandle.handle(msg);
		} 
		else if (msg.getEventType() == QueueTypeEnum.CARLOCK_OUTALARM.getType()) {
			// 锁车出场报警消息
			_log.info(" 锁车出场报警消息 :"+msg);
			CarlockOutalarmHandle carlockOutalarmHandle = SpringContextUtil.getApplicationContext().getBean(CarlockOutalarmHandle.class);
			carlockOutalarmHandle.handle(msg);
		} 
		else if (msg.getEventType() == QueueTypeEnum.INVITE_INCHECK.getType()) {
			// 邀请车辆进场消息
			_log.info(" 邀请车辆进场消息 :"+msg);
			InviteInckeckHandle inviteInckeckHandle = SpringContextUtil.getApplicationContext().getBean(InviteInckeckHandle.class);
			inviteInckeckHandle.handle(msg);
		} 
		else if(msg.getEventType() ==QueueTypeEnum.OUTLINE_MONTHLY_PAY.getType() ){
			//线下月租续费单上报
			OutlineMonthlyReportHandle outlineMonthlyReportHandle = SpringContextUtil.getApplicationContext().getBean(OutlineMonthlyReportHandle.class);
			outlineMonthlyReportHandle.handle(msg);
		}else if(msg.getEventType() ==QueueTypeEnum.EXPIRE_CAR_SMS.getType()){
			ExpireNoticeHandle expireNoticeHandle = SpringContextUtil.getApplicationContext().getBean(ExpireNoticeHandle.class);
			expireNoticeHandle.handle(msg);
		}else if(msg.getEventType() ==QueueTypeEnum.PASS_DAY_REPORT.getType()){
			//通行日报表
			PassDayReportHandle passDayReportHandle = SpringContextUtil.getApplicationContext().getBean(PassDayReportHandle.class);
			passDayReportHandle.handle(msg);
		}else if(msg.getEventType() ==QueueTypeEnum.RENEWALSYNC.getType()){
		    //车牌/卡续费消息上报   v1.0
		    RenewalSyncDTO renewalSyncDTO =data.toJavaObject(RenewalSyncDTO.class);
		    reportFacade.renewalSync(renewalSyncDTO);
		}else if(msg.getEventType() ==QueueTypeEnum.PARKINSYNC.getType()){
		  //入场记录上报   v1.0
		    ParkInSyncDTO parkInSyncDTO =data.toJavaObject(ParkInSyncDTO.class);
            reportFacade.parkInSync(parkInSyncDTO);
		}else if(msg.getEventType() ==QueueTypeEnum.EXCEPTION_PARKOUTSYNC.getType()){
		    //异常出场记录上报  v1.0
		    ExceptionParkOutSyncDTO exceptionParkOutSyncDTO =data.toJavaObject(ExceptionParkOutSyncDTO.class);
            reportFacade.exceptionParkOutSync(exceptionParkOutSyncDTO);
		}else if(msg.getEventType() ==QueueTypeEnum.PARKOUTSYNC.getType()){
		    //出场记录上报  v1.0
		    ParkOutSyncDTO parkOutSyncDTO =data.toJavaObject(ParkOutSyncDTO.class);
            reportFacade.parkOutSync(parkOutSyncDTO);
		}else if(msg.getEventType() ==QueueTypeEnum.PARKOUT_RENEWALSYNC.getType()){
		    //出/入场缴费记录上报 v1.0
		    ParkOutRenewalSyncDTO parkOutRenewalSyncDTO =data.toJavaObject(ParkOutRenewalSyncDTO.class);
            reportFacade.parkOutRenewalSync(parkOutRenewalSyncDTO);
		}else if(msg.getEventType() ==QueueTypeEnum.PARKEVENTSYNC.getType()){
		    //事件推送  v1.0
		    ParkEventSyncDTO parkEventSyncDTO =data.toJavaObject(ParkEventSyncDTO.class);
            reportFacade.parkEventSync(parkEventSyncDTO);
		}
		/******上报处理**********/
		else {
			_log.info("非法的队列消息::" + msg);
		}
	}
}
